/**
 * Copyright (C) 2014 Luvina Software Company
 * MstGroupDaoImpl.java, Dec 17, 2014, Nguyen Huu Luan LA11_AM
 *
 */
package net.luvina.manageuser.dao.impl;

import java.util.ArrayList;
import java.util.List;

import net.luvina.manageuser.dao.MstJapanDao;
import net.luvina.manageuser.entities.MstJapan;

/**
 * Thực thi giao diện MstJapanDao và lấy về danh sách trình độ tiếng Nhật trong
 * bảng mst_japan.
 * 
 * @author luan
 * 
 */
public class MstJapanDaoImpl extends BaseDaoImpl implements MstJapanDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see manageuser.dao.UserDao#getAllGroups()
	 */
	public List<MstJapan> getAllMstJapan() {
		List<MstJapan> lsJapan = new ArrayList<MstJapan>();
		if (connectToDB()) {
			try {
				StringBuilder sqlCommand = new StringBuilder();
				sqlCommand.append("SELECT mj.code_level, mj.name_level ");
				sqlCommand.append("FROM mst_japan AS mj ");
				sqlCommand.append(" ORDER BY mj. code_level ASC ");

				preparedStatement = connection.prepareStatement(sqlCommand
						.toString());

				rs = preparedStatement.executeQuery();

				if (rs != null) {
					while (rs.next()) {
						MstJapan japan = new MstJapan();
						japan.setCodeLevel(rs.getString("code_level"));
						japan.setCodeName(rs.getString("name_level"));
						lsJapan.add(japan);
					}
					rs.close();
				}

			} catch (Exception e) {
				System.out.println("an exception occur: " + e.getMessage());
			}
			closeConnect();
		}
		return lsJapan;
	}

}
